package desktop.local.pair.compete;

import pulpcore.Stage;
import pulpcore.scene.Scene2D;
import desktop.conf.key.KeyConfLeft;
import desktop.conf.key.KeyConfRight;
import desktop.core.bar.BarController;
import desktop.core.playfield.PlayFieldModel;
import desktop.core.playfield.PlayFieldViewSingleBar;
import desktop.playerguide.scoreForm.ScoreGroup;

public class LocalPairCompeteScene extends Scene2D {
	private PlayFieldViewSingleBar leftPlayFieldView;
	private PlayFieldViewSingleBar rightPlayFieldView;
	private ScoreGroup leftScoreForm;
	private ScoreGroup rightScoreForm;

	@Override
	public void load() {
		// playingfield on the left
		leftScoreForm = new ScoreGroup();
		rightScoreForm = new ScoreGroup();
		leftPlayFieldView = new PlayFieldViewSingleBar(0, 0,
				Stage.getWidth() * 0.48, Stage.getHeight(), new PlayFieldModel(
						9, 15, 3), new BarController(new KeyConfLeft()));
		this.add(leftPlayFieldView);
		leftScoreForm.setLocation(
				Stage.getWidth() * 0.5 - leftScoreForm.getW(), 0);
		this.add(leftScoreForm);

		// playingfield on the right ,its layout manager
		rightPlayFieldView = new PlayFieldViewSingleBar(
				Stage.getWidth() * 0.48, 0, Stage.getWidth() * 0.52, Stage
						.getHeight(), new PlayFieldModel(9, 15, 3),
				new BarController(new KeyConfRight()));
		this.add(rightPlayFieldView);
		rightScoreForm.setLocation(Stage.getWidth() - rightScoreForm.getW(), 0);
		this.add(rightScoreForm);
	}

	@Override
	public void update(int elapsedTime) {
		super.update(elapsedTime);
		leftScoreForm.setScore(leftPlayFieldView.getPointsTotally());
		rightScoreForm.setScore(rightPlayFieldView.getPointsTotally());
	}
}
